package cn.wolfcode.wms.service.impl;

import cn.wolfcode.wms.domain.Department;
import cn.wolfcode.wms.mapper.DepartmentMapper;
import cn.wolfcode.wms.page.PageResult;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper mapper;

    public void save(Department dept) {
        mapper.save(dept);
    }

    public void delete(long id) {
        mapper.delete(id);
    }

    public void update(Department dept) {
        mapper.update(dept);
    }

    public Department get(long id) {
        return mapper.get(id);
    }

    public List<Department> list() {
        return mapper.list();
    }

    public PageResult query(QueryObject qo) {
        int rows = mapper.queryForCount(qo);
        if (rows == 0) {
            return PageResult.empty(qo.getPageSize());
        }
        List<?> result = mapper.queryForList(qo);
        return new PageResult(result, rows, qo.getCurrentPage(), qo.getPageSize());
    }
}
